package com.atguigu.tingshu.user.rpc;

/**
 * @Author：yyj
 * @Package：com.atguigu.tingshu.user.rpc
 * @Project：tingshu_parent240829
 * @name：UserInfoRpcController
 * @Date：2025/1/19 22:41
 * @Filename：UserInfoRpcController
 */

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.user.service.VipServiceConfigService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/rpc/userinfo")
public class UserInfoRpcController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private VipServiceConfigService vipServiceConfigService;
    @GetMapping(value = "/getUserInfo/{userId}")
    @Operation(summary = "微服务获取用户基本信息")
    Result<UserInfoVo> getUserInfo(@PathVariable(value = "userId") Long userId){
        UserInfoVo userInfoVo = userInfoService.getUserInfo(userId);
        return Result.ok(userInfoVo);
    }

    @GetMapping(value = "/getUserPaidAlbumTrackList/{userId}/{albumId}")
    @Operation(summary = "查询用户是否买过声音")
    Result<Map<Long, String>> getUserPaidAlbumTrackList(@PathVariable(value = "userId") Long userId,
                                                        @PathVariable(value = "albumId") Long albumId){
            Map<Long, String> userInfo= userInfoService.getUserPaidAlbumTrackList(userId,albumId);
            return Result.ok(userInfo);
    }

    @GetMapping(value = "/getUserPaidAlbum/{userId}/{albumId}")
    Result<Boolean> getUserPaidAlbum(@PathVariable(value = "userId") Long userId,
                                     @PathVariable(value = "albumId") Long albumId) {
        Boolean isPaid=userInfoService.getUserPaidAlbum(userId,albumId);
        return Result.ok(isPaid);
    }

    @GetMapping(value = "/getAllVipConfig/{itemId}")
    Result<VipServiceConfig> getAllVipConfig(@PathVariable(value = "itemId") Long itemId) {
        VipServiceConfig byId = vipServiceConfigService.getById(itemId);
        return Result.ok(byId);
    }
}